﻿document.write("<script language='javascript' src='/resources/js/views/defineTable.js'></script>");
var allYear="/resources/js/views/allYear.do";
function loadYear(){
	$.get(allYear, function (json) {
		$("#comboboxYear").combobox({
			textField:"text",
			valueField:"id",
			width:'100px',
			height:'28px',
			data:json,
			multiple:true,
			editable:false,
			formatter:function(row){
				var opts;
				if(row.select=="true"){
					row.selected=true;
					opts = "<input type='checkbox' name='year' checked='checked' id='"+row.id+"' value='"+row.id+"'>"+row.text+"</input>";
				}else{
					opts = "<input type='checkbox' name='year' id='"+row.id+"' value='"+row.id+"'>"+row.text+"</input>";
				}
				return opts;
			},
			panelHeight:"auto",
			panelWidth:'100px',
			panelAlign:'left',
			onSelect:function(rec) {
				oCheckbox = document.getElementById(rec.id);
				oCheckbox.checked=true;
				queryList();
			},
			onUnselect:function(rec){
				oCheckbox = document.getElementById(rec.id);
				oCheckbox.checked=false;
				queryList();
			}
			// ,
			// onLoadSuccess:function(){
			// 	queryList();
			// }
		});
	},'json');
}

function getFirstYear() {
	var years=$('#comboboxYear').combobox('getText');
	var yearList= [];
	if(years!=null ||years!='' || years!=undefined){
		yearList=years.split(',');
	}
	yearList.sort(funcSort);
	return yearList[0];
}

function getYearList() {
	var years=$('#comboboxYear').combobox('getText');
	var yearList= [];
	if(years!=null ||years!='' || years!=undefined){
		yearList=years.split(',');
	}
	yearList.sort(funcSort);
	return yearList;
}

function getYears() {
	var years=$('#comboboxYear').combobox('getText');
	return years;
}

function funcSort (a,b) {
	return a-b;
}


function getReportShowColumns (){
	var reportShowColumns = [];
	var ck = {
		title : '',
		field : 'ck',
		checkbox : true,
		width : 90
	};
	reportShowColumns.push(ck);
	reportShowColumns.push(defineTableReportAllColumns["iname"]);// 指标名称
	reportShowColumns.push(defineTableReportAllColumns["code"]);// 指标名称
	reportShowColumns.push(defineTableReportAllColumns["unit"]);// 计量单位

	var yearList= getYearList();
	for (var i = 0; i < yearList.length; i++) {
		var c = {title : yearList[i], field : yearList[i], width : 90, align:"center",
			formatter : function(value, row, index) {
				if(value==null){
					return value;
				}
				if(value.indexOf('_')!=-1){
					value = value.split('_')[2];
				}
				return value;
			}
		};
		reportShowColumns.push(c);
	}
	reportShowColumns.push(defineTableReportAllColumns["sname"]);// 资料来源
	return reportShowColumns;
}
